package double_pointer;

import java.util.Arrays;

public class triangleNumber {
    public static void main(String[] args) {
        triangleNumber(new int[]{2,2,3,4});
    }
    public static int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int sum = 0;
        for (int i = nums.length - 1; i >= 2; i--) {
            int left = 0;
            int right = i - 1;
            while (left < right) {
                if (nums[left] + nums[right] <= nums[i]) {
                    left++;
                } else {
                    sum += right - left;
                    right--;
                }
            }


        }
        return sum;
    }
}
